package com.CST.controller.cb;


import cn.hutool.core.date.DateException;
import com.CST.common.api.ResultObject;
import com.CST.dto.cb.InvoiceRecordsDTO;
import com.CST.entity.cb.InvoiceRecords;
import com.CST.service.impl.cb.InvoiceRecordsServiceImpl;
import com.CST.util.PageHelperTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 发票记录表 前端控制器
 * </p>
 *
 * @author qtx
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/report/invoiceRecords")
public class InvoiceRecordsController {

    @Autowired
    private InvoiceRecordsServiceImpl invoiceRecordsService;

//    @PostMapping("/findPage")
//    public ResultObject<IPage<InvoiceRecordsVo>> findPage(@RequestBody InvoiceRecordsDto dto) {
//        IPage<InvoiceRecordsVo> result =invoiceRecordsService.findPage(dto);
//        int a =0;
//        return ResultObject.success(result);
//    }

    @PostMapping("/findPage")
    public ResultObject findPage(@RequestBody InvoiceRecordsDTO dto) {
        List<InvoiceRecords> result =invoiceRecordsService.findPage(dto);
        return ResultObject.success(PageHelperTool.excutePageInfo(result, dto.getNum(), dto.getSize()));
    }

    @PostMapping("/saveOrUpdate")
    public ResultObject<Boolean> saveOrUpdateInfo(@RequestBody InvoiceRecords info) throws Exception {
        return ResultObject.success(invoiceRecordsService.saveOrUpdateNew(info));
    }

    @DeleteMapping("/remove")
    public ResultObject<Boolean> remove(@RequestParam Long id) {
        return ResultObject.success(invoiceRecordsService.removeById(id));
    }

    @GetMapping("/download")
    public void downloadExcel(HttpServletResponse response) throws ClassNotFoundException {
        invoiceRecordsService.exportExcel(response);
    }
}
